package 作业2;

import java.util.Random;
import java.util.Scanner;

public class RockPaperScissors {

  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);
    Random random = new Random();

    System.out.println("欢迎来到石头、剪刀、布游戏!");
    System.out.println("请输入你的选择（石头(2)、剪刀(1)、布(0)）：");
    int userChoice = scanner.nextInt();

    int computerChoice = random.nextInt(3);

    String computerChoiceStr = getChoiceString(computerChoice);
    System.out.println("计算机出的是：" + computerChoiceStr);

    String userChoiceStr = getChoiceString(userChoice);
    String result = determineWinner(userChoice, computerChoice);

    System.out.println(
      "你出" + userChoiceStr + "，计算机出" + computerChoiceStr + "，" + result
    );
  }

  public static String getChoiceString(int choice) {
    switch (choice) {
      case 0:
        return "布";
      case 1:
        return "剪刀";
      case 2:
        return "石头";
      default:
        return "无效选择";
    }
  }

  public static String determineWinner(int userChoice, int computerChoice) {
    if (userChoice == computerChoice) {
      return "平局";
    } else if (
      (userChoice == 0 && computerChoice == 1) ||
      (userChoice == 1 && computerChoice == 2) ||
      (userChoice == 2 && computerChoice == 0)
    ) {
      return "你赢了";
    } else {
      return "计算机赢了！";
    }
    
  }
  
}
